//DHCOutPhLocAddCode
var SelectedRow = 0;
function BodyLoadHandler() {
	var baddobj=document.getElementById("BInsert");
	if (baddobj) baddobj.onclick=Badd_click;
	var obj=document.getElementById("BUpdate");
	if (obj) obj.onclick=Bupdate_click;
	//var GUserid=document.getElementById("userid");
   //var lnk = "websys.default.csp?WEBSYS.TCOMPONENT=DHCOutPhPerCode&userid="+GUserid;
 	//document.location.href=lnk;

}
function GetPharmacy(str) {

var ctlocobj=document.getElementById('ctloc');
var CPhLocDescobj=document.getElementById('CPhLocDesc');
var tem=str.split("^");

ctlocobj.value=tem[0];
CPhLocDescobj.value=tem[1];

}

function GetAddLoc(str) {

var ctlocobj=document.getElementById('OrdLoc');
var CPhLocDescobj=document.getElementById('OrdLocDesc');
var tem=str.split("^");
//alert(tem[1]);

ctlocobj.value=tem[0];
CPhLocDescobj.value=tem[1];

}
function SelectRowHandler()	{
	var eSrc=window.event.srcElement;
	var objtbl=document.getElementById('tDHCOutPhLocAddCode');
	var rows=objtbl.rows.length;
	var lastrowindex=rows - 1;
	var rowObj=getRow(eSrc);
	var selectrow=rowObj.rowIndex;
	if (!selectrow) return;
	var obj=document.getElementById('OrdLocDesc');
	var obj1=document.getElementById('OrdLoc');
	var obj2=document.getElementById('CPhLocDesc');
	var obj3=document.getElementById('ctloc');
	var obj4=document.getElementById('DoFlag');
	
	var SelRowObj=document.getElementById('TOrdLocDescz'+selectrow);
	var SelRowObj1=document.getElementById('TOrdLocz'+selectrow);
	var SelRowObj2=document.getElementById('TYFDescz'+selectrow);
	var SelRowObj3=document.getElementById('TYFDMz'+selectrow);
    var SelRowObj4=document.getElementById('TDoFlagz'+selectrow);
  
  
       
	obj.value=SelRowObj.innerText;
	obj1.value=SelRowObj1.value;
	obj2.value=SelRowObj2.innerText;
	obj3.value=SelRowObj3.value;
	if (SelRowObj4.innerText==t['yes']){obj4.checked=true}
	  else  {obj4.checked=false}
	SelectedRow = selectrow;
}

function Bupdate_click()	
{
	selectrow=SelectedRow;
	
	var rowid=document.getElementById('TPhlac_Rowidz'+selectrow).value
    var use=document.getElementById('DoFlag').checked;
    var useval=""
    if (use==true){use="1";useval=t['yes']}
    else
      {use="0";useval=t['no']}
  
     var pid=document.getElementById('up');
	if (pid) {var encmeth=pid.value} else {var encmeth=''};
	if (cspRunServerMethod(encmeth,rowid,use)!='0')
	 {	alert(t['upfail']);
	return;}
		
	else {		   
	    alert(t['upok']);
	    document.getElementById('TDoFlagz'+selectrow).innerText=useval
	    
		}
	

}

function GUserId(value)	
{
 var usercode=document.getElementById('CUserCode')
 var userid=document.getElementById('CUserid')

var vstr=value
 var sstr=vstr.split("^")
 usercode.value=sstr[1]
 userid.value=sstr[2]
 // alert(value)	
}

function Badd_click()	
{
	//selectrow=SelectedRow;
	var ctloc=document.getElementById('ctloc').value;
	var phlocdesc=document.getElementById('CPhLocDesc').value;
	if (ctloc=="") {
		alert(t['pharmacyisnull'])
		return;}
	var ordloc=document.getElementById('OrdLoc').value;
	if (ordloc=="") {
		alert(t['ordlocisnull'])
		return;}
    var use=document.getElementById('DoFlag').checked;

    if (use==true){use="1";}
    else
      {use="0";}
   
     var pid=document.getElementById('ins');
	if (pid) {var encmeth=pid.value} else {var encmeth=''};
	var retval=cspRunServerMethod(encmeth,ctloc,ordloc,use)
	 if (retval=="-2"){alert(t['ordlochadcode']);return;}
	 else if (retval!=0){alert(t['insfail']);return;}
	 else
	 {alert(t['insok']);
	  var lnk = "websys.default.csp?WEBSYS.TCOMPONENT=DHCOutPhLocAddCode&CPhLocDesc="+phlocdesc+"&ctloc="+ctloc
   location.href=lnk;
  

	//window.location.reload();
	 }

}
function SetPid(value) 
{  
	if (value!="0")
	{alert(t['05']);
	return;
		}
	try {		   
	    alert(t['06']);
	    window.location.reload();
		} catch(e) {};
}
function CleartDHCOPAdm()
{
	var objtbl=document.getElementById('tDHCOPReturn');
	var rows=objtbl.rows.length;
	var lastrowindex=rows-1;
	for (var j=1;j<lastrowindex+1;j++) {
		objtbl.deleteRow(1);
	//alert(j);
	}
}
document.body.onload = BodyLoadHandler;